import request from '@/utils/request'

// 添加文章
export function addArticle(data) {
    return request({
        url: '/article/addarticle',
        method: 'post',
        data
    })
}

// 上传图片
export function uploadImage(file) {
    const formData = new FormData()
    formData.append('file', file)
    return request({
        url: '/article/pullimages',
        method: 'post',
        data: formData,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

// 获取文章详情
export function getArticleDetail(articleId) {
    return request({
        url: `/public/article/get_article/${articleId}`,
        method: 'get'
    })
}



export function getArticleCards(pageNum, pageSize) {
    return request({
        url: '/public/article/pages',
        method: 'get',
        params: {
            pageNum,
            pageSize
        }
    })
}
export function getArticle(id) {
    return request({
        url: `/public/article/get_article/${id}`,
        method: 'get'

    })
}

//根据分类获取文章
export function getArticleListbycategory(categoryId, pageNum = 1, pageSize = 5) {
    return request({
        url: `/public/category/page/${categoryId}`,
        method: 'get',
        params: {
            pageNum,
            pageSize
        }
    })
}

export function getArticleListbytag(tagId, pageNum = 1, pageSize = 5) {
    return request({
        url: `/public/tag/page/${tagId}`,
        method: 'get',
        params: {
            pageNum,
            pageSize
        }
    })
}


export function getTagNameById(tagId) {
    return request({
        url: `/public/tag/tagname/${tagId}`,
        method: 'get'
    })
}

export function getCategoryNameById(categoryId) {
    return request({
        url: `/public/category/categoryname/${categoryId}`,
        method: 'get'
    })
}

export function getSidebar() {
    return request({
        url: `/public/sidebar`,
        method: 'get'
    })
}

export const getTagList = () => {
    return request({
        url: '/public/tag/list',
        method: 'get'
    })
}

export const getCategoryList = () => {
    return request({
        url: '/public/category/list',
        method: 'get'
    })
}